<?php
namespace Org\Oa;
class common{
	/**
	 *  无限极分类递归函数
	 */
	public static function sortdata($catArray, $id = 0 , $prefix = '',$type=0)
	{
		static  $formatCat = array();
		static  $floor     = 0;
		foreach($catArray as $key => $val)
		{
			if($val['parent_id'] == $id)
			{
				$str         = self::nstr($prefix,$floor);
				$val['name'] = $str.$val['name'];
				/* $val['floor'] = $floor; */
				$formatCat[]  = $val;
				unset($catArray[$key]);
				$floor++;
				self::sortdata($catArray, $val['id'] ,$prefix);
				$floor--;
			}
		}
		//$newarray = $catArray;
		//unset($formatCat);
		return $formatCat;
	}
	public static function unlimitedForLevel ($cate, $html = '--', $pid = 0, $level = 0) {
		$arr = array();
		foreach ($cate as $k => $v) {
			if ($v['parent_id'] == $pid) {
				$v['level'] = $level + 1;
				$str         = self::nstr($html,$level);
				$v['name'] = $str.$v['name'];
				$arr[] = $v;
				$arr = array_merge($arr, self::unlimitedForLevel($cate, $html, $v['id'], $level + 1));
			}
		}
		return $arr;
	}
	//处理商品列表显示缩进
	public static function nstr($str,$num=0)
	{
		$return = '';
		for($i=0;$i<$num;$i++)
		{
		$return .= $str;
		}
		return $return;
	}
	function unique_arr($array2D,$stkeep=false,$ndformat=true)
	{
	    // 判断是否保留一级数组键 (一级数组键可以为非数字)
	    if($stkeep) $stArr = array_keys($array2D);
	    // 判断是否保留二级数组键 (所有二级数组键必须相同)
	    if($ndformat) $ndArr = array_keys(end($array2D));
	    //降维,也可以用implode,将一维数组转换为用逗号连接的字符串
	    foreach ($array2D as $v){
	        $v = join("+",$v); 
	        $temp[] = $v;
	    }
	    //去掉重复的字符串,也就是重复的一维数组
	    $temp = array_unique($temp); 
	    //再将拆开的数组重新组装
	    foreach ($temp as $k => $v)
	    {
	        if($stkeep) $k = $stArr[$k];
	        if($ndformat)
	        {
	            $tempArr = explode("+",$v); 
	            foreach($tempArr as $ndkey => $ndval) $output[$k][$ndArr[$ndkey]] = $ndval;
	        }
	        else $output[$k] = explode("+",$v); 
	    }
	    return $output;
	}
	public function sortsort($k,$name=null){
		if(empty($name)){
			$name = "&nbsp;&nbsp;";
		}
		if($k){
			for ($i=0;$i<$k;$i++){
				$a .= $name;
			}
		}
		return $a;
	}
	public static function ceshi(){
		return 123;
	}
}